import {observable,action} from 'mobx';
import {getShopdata} from '../../api/shop';

export default class Car{
    @observable list = [];
    @observable total = 0;

    getTotal = () => {
        return this.list.reduce((prev,cur) => {
            return prev += cur.price*cur.count
        },0)
    }

    @action 
    getShopList = async () => {
        let res = await getShopdata();
        this.list = res.data.data;
        this.total = this.getTotal();
    }

    @action
    changeShopCar = (flag,id) => {
        this.list[id].count = flag ? this.list[id].count + 1:this.list[id].count-1;
        this.total = this.getTotal();
    }
}